package com.abcdefg.springtrans.controller;

import com.abcdefg.springtrans.service.LogService;
import com.abcdefg.springtrans.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/propaga")
@RestController
public class PropagationController {
    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;

    @Transactional(propagation = Propagation.REQUIRED)
//    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @RequestMapping("r3")
//    @Transactional(propagation = Propagation.NESTED)
//    @Transactional(propagation = Propagation.NOT_SUPPORTED)
//    @Transactional(propagation = Propagation.NEVER)
    public String r3(String name,String password){
        userService.registryUser(name,password);

        logService.insertLog(name,"用户注册");

        return "success";
    }
}
